

/**
 * 弹出窗体
 * @param url {弹出窗体装载URL} 
 * @param wWidth {弹出窗体宽度} 
 * @param wHeight {弹出窗体高度}
 */
function popWindow(url ,wWidth ,wHeight){
	createEXTWindow(url ,wWidth,wHeight);
}

var extWin;
/**
 * 创建ext弹出窗体
 * @param url {弹出窗体装载URL} 
 * @param wWidth {弹出窗体宽度} 
 * @param wHeight {弹出窗体高度}
 */
function createEXTWindow(url ,wWidth ,wHeight){
	try{
		extWin = null;
		if(!extWin){
		    extWin = new Ext.Window({
		        title: '',
				modal:true,
		        width: wWidth,
		        height: wHeight,
		        minWidth: 100,
		        minHeight: 100,
		       // layout: 'fit',
		       // plain:true,
				maximizable:true,
				listeners: {  
                    close:function(w){  
                        //关闭窗口前先还原,滚动条才不会消失  
                        w.restore();  
                    },  
                    maximize:function(w){      
                        //最大化后需要将窗口重新定位，否则窗口会从最顶端开始最大化                          
                        w.setPosition(document.body.scrollLeft-4,document.body.scrollTop-4);  
                    }
                },
				closable:true,
		        //bodyStyle:'padding:5px;',
		        buttonAlign:'center',
				html:createIframe('ext-win-iframe' , url , 'popWindow')
		    });
		    extWin.show();
		    //jQuery('#win-iframe').attr('src', url);
		}
	}catch(e){}
}

/**
 * 创建DIV弹出窗体,模拟转页效果,以便保存主页数据状态
 * @param {窗体装载URL} url
 */
function createDIVWindow(url){
	var divWin = document.createElement('DIV');
    divWin.id = 'divwin';
    divWin.style.position = 'absolute';
    divWin.style.left = "0px";
    divWin.style.top = "0px";
    divWin.style.width = "100%";
    divWin.style.height = "100%";
    divWin.style.background ='#dfe8f6';
    divWin.style.zIndex = "10000";
    var str = createIframe('div-win-iframe' , url , 'linkWindow');
    divWin.innerHTML = str;
    document.body.appendChild(divWin);
}

/**
 * @param iframeId {iframe Id}
 * @param url {装载URL} 
 * @param windowType {窗体类型} 
 */
function createIframe(iframeId , url , windowType){
	return '<iframe id='+iframeId+' frameborder="0" ' +
			'src='+getGotoUrl(url,windowType)+' scrolling="auto" ' +
				//'onload="this.height='+iframeId+'.document.body.scrollHeight"' +
					'width="100%" height="100%" ></iframe>';
}

//getGotoUrl
//function getGotoUrl(url ,windowType){
//	return 'container.jsp?windowType='+windowType+'&gotoUrl=' + url;
//}
function getBasePase(){
	//获取当前程序根目录
	var strFullPath=window.document.location.href;
	var strPath=window.document.location.pathname;
	var pos=strFullPath.indexOf(strPath);
	var prePath=strFullPath.substring(0,pos);
	var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
	return prePath + postPath;
}


function getGotoUrl(gotoUrl /*,windowType*/){
	return gotoUrl;//不跳转
	/*方法一
	if(gotoUrl.indexOf('&')!=-1){
		var regS = new RegExp("&","gi");
		gotoUrl = gotoUrl.replace(regS,'-');
	}
	*/
	/*方法二*/
	if(gotoUrl.indexOf('&')!=-1){
		var url=gotoUrl.replace('&','|');
		do{
			gotoUrl = url;
			url = url.replace('&','|');
		}while(url!=gotoUrl)
	}

	var wait = getBasePase() + "/wait.jsp?gotoUrl='"+gotoUrl+"'";
	return wait;
	/*
	if(gotoUrl.indexOf('?') != -1){
		return wait + '|windowType='+windowType+"'";
	}else{
		return wait + '?windowType='+windowType+"'";
	}*/
}

/**
 * @param {装载URL} url
 * @param {转页的Iframe Id} linkIframeId
 */
function linkWindow(url ,linkIframeId){
	if(jQuery("#dataArea") != null){
		jQuery("#dataArea").css("display","none");
	}
	/**
	 * update for 2008-10-16
	 */
	if(linkIframeId!=undefined){
		jQuery('#'+linkIframeId).attr('src', getGotoUrl(url,'linkWindow'));
		return;
	}
	if(url!=undefined){
		createDIVWindow(url);
	}
	/*
	if(iframeId!=undefined){
		jQuery('#'+iframeId).attr('src', getGotoUrl(url,'linkWindow'));
		return;
	}
	location = getGotoUrl(url,'linkWindow');
	*/	
}

/**
 * 关闭窗体,包括ext弹出窗体和div模拟窗体两种
 */
function closeWin(){
	try{
		parent.jQuery("#dataArea").css("display","block");//解决linkWindow覆盖不了父页面
	}catch(e){}
	try{
		var ecsideObj= parent.ECSideUtil.getGridObj("ec");
		ecsideObj.init();//解决重新显示EcSide后标题与数据对不起
	}catch(e){
		try{
			var ecsideObjGroup= parent.ECSideUtil.getGridObj("groupec");
			ecsideObjGroup.init();//解决重新显示EcSide后标题与数据对不起
			
			var ecsideObjPerson= parent.ECSideUtil.getGridObj("personec");
			ecsideObjPerson.init();//解决重新显示EcSide后标题与数据对不起
		}catch(e){}
	}	
	
	if(parent.jQuery('#divwin')!=null){
		parent.jQuery('#divwin').remove();
	}
	if(parent.extWin!=null){
		parent.extWin.close();
	}
}

/**
 * div模拟窗体返回
 */
function back(url ,linkIframeId){
	try{
		parent.jQuery("#dataArea").css("display","block");//解决linkWindow覆盖不了父页面
	}catch(e){}
	try{
		var ecsideObj= parent.ECSideUtil.getGridObj("ec");
		ecsideObj.init();//解决重新显示EcSide后标题与数据对不起
	}catch(e){
		try{
			var ecsideObjGroup= parent.ECSideUtil.getGridObj("groupec");
			ecsideObjGroup.init();//解决重新显示EcSide后标题与数据对不起
			
			var ecsideObjPerson= parent.ECSideUtil.getGridObj("personec");
			ecsideObjPerson.init();//解决重新显示EcSide后标题与数据对不起
		}catch(e){}
	}	
	
	if(parent.jQuery('#divwin')){
		parent.jQuery('#divwin').remove();
		return;
	}
}

/**
 * 验证
 * @param validatorgroupIds {需要验证的控件组ID} 
 */
function validator(validatorgroupIds){
	if(validatorgroupIds != undefined){
		var valigroupIds = validatorgroupIds.split(",");
		for(i=0;i<valigroupIds.length;i++){
			if(!(jQuery.formValidator.pageIsValid(valigroupIds[i]))){
				return false;
			}
		}
	}else if(validatorgroupIds == undefined){
		if(!(jQuery.formValidator.pageIsValid())){
			return false;
		}
	}
	return true;
}

/**
 * 设置验证需要验证和不需要验证的控件组
 * @param unvalIds {不需要验证的控件组ID} 
 * @param valIds {需要验证的控件组ID}
 */
function unvalidator(unvalIds, valIds){
	if(unvalIds!=undefined){
		var unIds = unvalIds.split(",");
		//不校验
		for(i=0;unIds!=undefined&&i<unIds.length;i++){
			jQuery("#"+unIds[i]).unFormValidator(true);
			//jQuery("#"+unIds[i]).attr("disabled",true).unFormValidator(true);
		}
	}
	if(valIds!=undefined){
		//校验
		var Ids = valIds.split(",");
		for(i=0;Ids!=undefined&&i<unIds.length;i++){
			jQuery("#"+valIds[i]).unFormValidator(false);
			//jQuery("#"+valIds[i]).attr("disabled",false).unFormValidator(false);
		}
	}
}

/**
 * 删除多条记录确定提示
 * @param ecId {ec:table id} 
 * @param idsname {多选框name} 
 * @param func {执行删除方法名}
 */
function deleteSConfirm(url,cids,succCallBack){
	var chIds = getCheckboxValue(cids);
	if(chIds==''){
		Ext.MessageBox.alert('消息', '请选择要删除的项!'); 
		return;
	}
	ajaxSend(url,'确定【删除】选中项的数据吗?',succCallBack);
}

/**
 * 删除单条记录确定提示
 * @param url {url} 
 */
function deleteConfirm(url,succCallBack){
	ajaxSend(url,'确定【删除】该条数据吗?',succCallBack);
}

/**
 * ajax方式提交
 * @param url 
 */
function ajaxSend(url,msg,succCallBack){
	if(msg==undefined){
		jQueryAjax(url);
		return;
	}else{
		Ext.MessageBox.confirm('消息', msg,function (btn){
			if(btn == 'yes'){
				jQueryAjax(url,succCallBack);
			}
		});
	}
}

function jQueryAjax(url,succCallBack){
	jQuery('#info').css('display','block');
	jQuery('#info').addClass('actionMessage');
	jQuery('#info').html("<img src='"+getBasePase()+"/images/process.gif'>");
	jQuery.ajax({
		url: url,
		ifModified:"0",
		success:function(res){
			jQuery("#info").html(res);
			refresh();
			if(succCallBack != null && succCallBack != undefined){//处理回调函数zmh
				if(jQuery.isFunction(succCallBack)){
					succCallBack();	
				}
			}
			//设置提示消息3秒钟后消失
			setTimeout(function(){jQuery('#info').css('display','none');return;},5000); 
		},
		error:function(msg) {
			jQuery("#info").removeClass('actionMessage');
			jQuery("#info").html('');
			Ext.MessageBox.alert('消息', '当前操作失败!');
		}
	});
}

//menu-close
function menuCloseOpen(){
	var w = Ext.getCmp('gncd');
	w.collapse(); 
}

function infoAlert(msg){
	Ext.MessageBox.alert('消息', msg);
}

/**
 * 获取多个checkbox的值
 * @param {} checkName
 */
function getCheckboxValue(checkName){
	var checkValue = "";
	jQuery("input[@name="+checkName+"][@checked]").each(function(){ 
		checkValue += jQuery(this).val()+",";
    })
    return checkValue;
}

/**
 * 获取select已选择的文本或者值
 * @param {通过id或name查找} pro
 * @param {id或name查找} selectName
 * @param {text或value} type
 */
function getSelectVal(pro,selectName,type){
	var selectValue = "";
	jQuery("select[@"+pro+"="+selectName+"] option[@selected]").each(function(){ 
		if(type=='text'){
			selectValue += jQuery(this).text();
		}else if(type=='value'){
			selectValue += jQuery(this).val();
		}
    });
    return selectValue;
}

//information
function info(){
	Ext.MessageBox.alert('消息', '验证未通过，请看错误提示!');
}


//封装系统alert
/*
window.alert = function(txt){
	Ext.MessageBox.alert('消息',txt);
}
*/

//文本框回车相当于按Tab键
function EnterToTab(id){
	if(window.event){
		keyPressed = window.event.keyCode; //IE
	}else{
		keyPressed = e.which; //Firefox
	}
	if(keyPressed==13){
		if(id != null){
			var txt = document.getElementById(id);
			if(txt != null){
				txt.focus();
				if(txt.type == "text"){
					txt.select();
				}
			}
		}
		else{
			window.event.keyCode = 9;
		}		
	}				
}

